package com.cherish.pattern.proxy.dynamicproxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Classname MeiPoProxy
 * @Date 2019/4/7 17:20
 * @Author admin
 * @Description TODO
 */
public class MeiPoProxy implements InvocationHandler {

    private Object target;

    public Object getInstants(Object target){
        this.target = target;
        Class clasz = target.getClass();
        return Proxy.newProxyInstance(clasz.getClassLoader(),clasz.getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        this.before();
        return method.invoke(this.target,args);
    }

    private void before(){
        System.out.println("jdk before");
    }
}
